package org.wisdom.data.jpa.support.service;

import javax.persistence.LockModeType;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.wisdom.data.jpa.support.entity.CodeGenerator;

/**
 * 编码生成实体仓储
 *
 * @author 张智研
 * @date 2022/05/18 17:32
 **/
interface CodeGeneratorRepository extends JpaRepository<CodeGenerator, String> {

    /**
     * 获取编码
     *
     * @author 张智研
     * @date 2022/05/18 17:45
     * @param genName
     *            编码名称
     * @return org.wisdom.data.jpa.support.entity.CodeGenerator
     */
    @Lock(value = LockModeType.PESSIMISTIC_WRITE)
    @Query(value = "select j from CodeGenerator j where j.genName = :genName ")
    CodeGenerator findByIdForUpdate(@Param("genName") String genName);
}
